package com.huixiong;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <描述>
 *
 * @author timothy.yang cloudwise
 * @since 2021-09-27 09:40
 */
public class stream_test {

    @Test
    public void group_by_test() {
        List<Student> students = Lists.newArrayList(new Student(1, "qwf","fm"),
                new Student(2, "wf12","m"),
                new Student(3, "13g","fm"),
                new Student(4, "f31","fm"),
                new Student(5, "aaa","m")
                );
        Map<String, List<Student>> collect = students.stream().collect(Collectors.groupingBy(Student::getType));
        System.out.println(collect);

    }

    @AllArgsConstructor
    @Data
    class Student {
        public Integer id;
        public String name;
        public String type;
    }
}
